﻿namespace dogd
{
	using System.IO;
	using System.Reflection;
	using System.Text;

	/// <summary>
	/// ScriptReader retrieves embedded sql scripts from resources.
	/// </summary>
	public static class ScriptReader
	{
		/// <summary>
		/// Read script from embedded resource in assembly.
		/// </summary>
		/// <param name="assembly"></param>
		/// <param name="fullyQualifiedResourceName"></param>
		/// <returns></returns>
		public static string ReadFromResource(Assembly assembly, string fullyQualifiedResourceName)
		{
			string text = string.Empty;

			using (var s = assembly.GetManifestResourceStream(fullyQualifiedResourceName))
			{
				if (s != null)
				{
					using (var sr = new StreamReader(s, Encoding.Default))
					{
						text = sr.ReadToEnd();
					}
				}
			}

			return text;
		}
	}
}
